<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateLessonsTable extends Migration
{

    protected $tableName = 'lessons';

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create($this->tableName, function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('course_id')->comment('课程ID');

            $table->string('name')->comment('课时名称');
            $table->string('description')->comment('课程描述');

            $table->unsignedSmallInteger('word_count')->default(0)->comment('单词数量');
            $table->unsignedSmallInteger('knowledge_count')->default(0)->comment('知识点数量');
            $table->unsignedSmallInteger('essence_qa_count')->default(0)->comment('精读问答数量');
            $table->unsignedSmallInteger('game_test_count')->default(0)->comment('游戏数量');
            $table->unsignedSmallInteger('game_word_count')->default(0)->comment('游戏单词数量');


            $table->string('lexile')->comment('蓝思指数');
            $table->json('introduction')->comment('导读');

            $table->unsignedInteger('name_audio')->comment('名称的音频附件ID');
            $table->unsignedInteger('cover')->comment('封面图片附件ID');
            $table->unsignedInteger('thumb_cover')->comment('封面缩略图附件ID');

            $table->unsignedInteger('studied_count')->default(0)->comment('学习人次');

            $table->unsignedSmallInteger('sequence')->comment('课时排序');
            $table->unsignedTinyInteger('is_published')->default(0)->comment('是否发布');

            $table->timestamps();
            $table->softDeletes();

            $table->index('course_id');
        });
        DB::statement("ALTER TABLE `$this->tableName` comment '课时表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists($this->tableName);
    }
}
